package edu.nf.project.mappers.storeOperation.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.entity.other.dto.CustomerOrderInfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author gjh
 * @Date 2025/6/4
 * @Description:
 */
@Mapper
public interface CustomerOrderDTOMapper extends BaseMapper<CustomerOrderInfoDTO> {
    @Select("SELECT \n" +
            "    co.order_id AS 订单编号,\n" +
            "    CASE co.order_type \n" +
            "        WHEN 1 THEN '堂食'\n" +
            "        WHEN 2 THEN '外卖'\n" +
            "        ELSE '未知'\n" +
            "    END AS 订单类型,\n" +
            "    b.board_name AS 餐桌名称,\n" +
            "    CASE co.order_status\n" +
            "        WHEN 0 THEN '已支付'\n" +
            "        WHEN 1 THEN '待支付'\n" +
            "        WHEN 2 THEN '已取消'\n" +
            "        ELSE '未知'\n" +
            "    END AS 订单状态,\n" +
            "    co.place_order_time AS 下单时间,\n" +
            "    d.dish_name AS 菜品名称,\n" +
            "    coi.quantity AS 菜品数量,\n" +
            "d.dish_image as 菜品图片,\n" +
            "    d.price AS 单价,\n" +
            "    (d.price * coi.quantity) AS 小计,\n" +
            "    co.total_amount AS 总计金额,\n" +
            "    co.discount_amount AS 优惠金额,\n" +
            "    co.payable_amount AS 实付金额\n" +
            "FROM customer_order_item coi\n" +
            "JOIN customer_order co ON coi.order_id = co.order_id\n" +
            "JOIN dish d ON coi.dish_id = d.dish_id\n" +
            "Left JOIN board b ON co.board_id = b.board_id\n" +
            "WHERE co.u_id = #{u_id}   -- 替换为具体操作人ID\n" +
            "ORDER BY co.place_order_time DESC;")
    List<CustomerOrderInfoDTO> getOrderByOrderUId(String u_id);

    /**
     * 根据订单编号查找订单深信息
     * @param orderId 订单编号
     * @return
     */
    @Select("SELECT \n" +
            "    co.order_id AS 订单编号,\n" +
            "    CASE co.order_type \n" +
            "        WHEN 1 THEN '堂食'\n" +
            "        WHEN 2 THEN '外卖'\n" +
            "        ELSE '未知'\n" +
            "    END AS 订单类型,\n" +
            "    b.board_name AS 餐桌名称,\n" +
            "    CASE co.order_status\n" +
            "        WHEN 0 THEN '已支付'\n" +
            "        WHEN 1 THEN '待支付'\n" +
            "        WHEN 2 THEN '已取消'\n" +
            "        ELSE '未知'\n" +
            "    END AS 订单状态,\n" +
            "    co.place_order_time AS 下单时间,\n" +
            "    d.dish_name AS 菜品名称,\n" +
            "    coi.quantity AS 菜品数量,\n" +
            "    d.price AS 单价,\n" +
            "    (d.price * coi.quantity) AS 小计,\n" +
            "    co.total_amount AS 总计金额,\n" +
            "    co.discount_amount AS 优惠金额,\n" +
            "    co.payable_amount AS 实付金额\n" +
            "FROM customer_order_item coi\n" +
            "JOIN customer_order co ON coi.order_id = co.order_id\n" +
            "JOIN dish d ON coi.dish_id = d.dish_id\n" +
            "JOIN board b ON co.board_id = b.board_id\n" +
            "WHERE coi.order_id = #{orderId} \n" +
            "ORDER BY co.place_order_time DESC;")
    List<CustomerOrderInfoDTO> listOrderById(String orderId);
}
